package com.demo.order;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;

/**
 * 订单服务启动类
 * 
 * @author demo
 * @since 1.0.0
 */
@SpringBootApplication(scanBasePackages = {"com.goods.feign.fallback", "com.demo.order"})
@EnableDiscoveryClient // 启用服务发现客户端
@EnableFeignClients(basePackages = {"com.goods.feign.client"}) // 启用Feign客户端，指定扫描包路径
@Slf4j
public class OrderServiceApplication {
    
    /**
     * 应用程序入口方法
     * 
     * @param args 命令行参数
     */
    public static void main(String[] args) {
        try {
            ApplicationContext context = SpringApplication.run(OrderServiceApplication.class, args);
            Environment env = context.getEnvironment();
            String port = env.getProperty("server.port", "8080");
            String appName = env.getProperty("spring.application.name", "order-service");
            
            log.info("=================================================");
            log.info("订单服务 [{}] 启动成功！", appName);
            log.info("服务端口: {}", port);
            log.info("环境配置: {}", env.getActiveProfiles().length > 0 ? 
                String.join(",", env.getActiveProfiles()) : "default");
            log.info("=================================================");
        } catch (Exception e) {
            log.error("订单服务启动失败: {}", e.getMessage(), e);
            System.exit(1);
        }
    }
}
